<?php

namespace login\model;

require_once("LoginDAL.php");
require_once("User.php");

class Loginmodel {
	/**
	 * @param  string $usrName
	 * @param  string $passWord
	 * @return boolean
	 * @throws Exception om något inte stämmer
	 */
	public function validateUsrInfo($usrName, $passWord) {
		if(empty($usrName)) {
			throw new \Exception("Användarnamn saknas");
		}
		if(empty($passWord)) {
			throw new \Exception("Lösenord saknas");
		}
		$user = new User("", "");
		try {
			$mysqli = new \mysqli("mysql08.citynetwork.se", "119958-mg18906",
							  "quizzer50", "119958-quizzer");
			$user = LoginDAL::getUser($usrName, $mysqli);
		} catch (\Exception $e) {
			
		} finally {
			$mysqli->close();
		}
		if($usrName != $user->getUsername() || $passWord != $user->getPassword()) {
			throw new \Exception("Felaktigt användarnamn och/eller lösenord");
		}
		return true;
	}
}